package com.rabbitmq.provider;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.Resources;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 * User: lixiao
 * Created Date: 2020/4/25 22:45
 */
@RestController
@RequestMapping(value = "/mq")
public class controller {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping(value = "/set")
    public Map set() {
        System.out.println("***************************进入请求**************");
        String uuid = String.valueOf(UUID.randomUUID());
        String msgData = "hello i am from provider";
        String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
        Map<String, Object> map = new HashMap();
        map.put("oid", uuid);
        map.put("msgData", msgData);
        map.put("date", date);
        rabbitTemplate.convertAndSend("testDirectExchange", "TestDirectRouting", map);
        return map;
    }

}